﻿using System;
using System.Text;
using SSG.Model;

namespace SSG.Tools
{
    /// <summary>
    /// Tool for ESE and SCT files
    /// </summary>
    public static class EseSct
    {
        /// <summary>
        /// .net type to string for ESE/SCT files
        /// </summary>
        /// <param name="type"></param>
        /// <param name="abbreviatedChars"></param>
        /// <returns></returns>
        public static String TypeToSctEseString(this Type type, int abbreviatedChars = -1)
        {
            string t;
            if (type == typeof (Sid))
                t = "SIDs";
            else if (type == typeof (Star))
                t = "STARs";
            else if (type == typeof (Transition))
                t = "TRANSITIONs";
            else
                throw new ArgumentException("Type " + type.FullName + " not supported");
            return abbreviatedChars < 1 ? t : t.Substring(0, abbreviatedChars);
        }

        /// <summary>
        /// File header for ESE / SCT files
        /// </summary>
        /// <param name="type"></param>
        /// <param name="name"></param>
        /// <param name="airacInfo"></param>
        /// <returns></returns>
        public static String EseSctFileHeader(this Type type, string name, string airacInfo = null)
        {
            if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
            StringBuilder sb = new StringBuilder(Generator.SctEseOutputHeader);
            sb.Append(' ');
            sb.Append(EseSct.TypeToSctEseString(type));
            sb.Append(' ');
            sb.Append(name);
            sb.Append('\n');
            if (!String.IsNullOrEmpty(airacInfo)) {
                sb.Append(Generator.SctEseOutputCommentCr);
                sb.Append(Generator.SctEseOutputCommentSpace);
                sb.Append(airacInfo);
                sb.Append('\n');
                sb.Append(Generator.SctEseOutputCommentCr);
            }
            return sb.ToString();
        }
    }
}